package com.venn.service.imp;

import com.alibaba.druid.util.StringUtils;
import com.venn.controller.UserController;
import com.venn.dao.ToDoListMapper;
import com.venn.entity.ToDoList;
import com.venn.service.ToDoListService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Venn on 2017/8/1.
 */
@Service("toDoListService")
public class ToDoListServiceImp implements ToDoListService{
    private static Logger logger = LogManager.getLogger(UserController.class.getName());
    /**
     * 在service定义：不需要再写setDao的方法就可以通过接口调用Dao
     */
    @Autowired
    private ToDoListMapper toDoListMapper;

    @Override
    public List<ToDoList> findAll(String userId) {
        return toDoListMapper.findAll(userId);
    }

    @Override
    public int create(ToDoList toDoList) {

        return toDoListMapper.create(toDoList);
    }

    @Override
    public boolean finish(String jobId,String flag) {

        if (!StringUtils.isEmpty(jobId) && !StringUtils.isEmpty(flag)){

            ToDoList toDoList = new ToDoList();
            toDoList.setId(jobId);
            toDoList.setFlag(flag);
            return toDoListMapper.finish(toDoList);
        }
        return false;
    }

    @Override
    public boolean finishSelect(String[] ids) {
        return toDoListMapper.finishSelect(ids);
    }

    @Override
    public boolean modify(String jobId, String content) {
        if (!StringUtils.isEmpty(jobId) && !StringUtils.isEmpty(content)){

            ToDoList toDoList = new ToDoList(jobId,content);
            return toDoListMapper.modify(toDoList);
        }
        return false;
    }

    @Override
    public boolean remove(String deleteflag) {

        return toDoListMapper.remove(deleteflag);
    }
}
